<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8"/>
    <title>商户列表</title>
	<link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
	<link href="${ctx}/static/dist/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
	<link href="${ctx}/static/plugins/datatables/css/matrix-style.css" rel="stylesheet" type="text/css"/>
	<link href="${ctx}/static/dist/css/AdminLTE.css" rel="stylesheet" type="text/css"/>
	<link href="${ctx}/static/plugins/datatables/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css"/>
    <style>
        button.searching{
            background-color:#666
        }
    </style>
</head>
<body>
<div class="widget-box">
	<div class="widget-title">
	   <h5>请输入查询条件</h5>
	</div>
	<div class="widget-content nopadding">
		<table style="line-height:45px;font-size:12px;">
			<tr>
				<td>&nbsp;&nbsp;&nbsp;商店名称：</td>
				<td><input type="text" class="form-control" name="merchantName" id="merchantName"  style="width:200px;" placeholder="请输入你的信息" ></td>
				<td>&nbsp;&nbsp;&nbsp;商户联系电话：</td>
				<td><input type="text" class="form-control" name="merchantTel" id="merchantTel"  style="width:200px;" placeholder="请输入你的信息" ></td>
				<td>&nbsp;&nbsp;&nbsp;推广师电话：</td>
				<td><input type="text" class="form-control" name="promoterTel" id="promoterTel"  style="width:200px;" placeholder="请输入你的信息" ></td>
				<td>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-success" href="javascript:void(0);"
                                                     onclick="query();">查 询</a>
				</td>
				<%--<td>--%>
				<%--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-primary" href="${ctx}/api/merchant/addMerchantAndMerchantImage">新增</a>--%>
				<%--</td>--%>
			</tr>
		</table>
        <%--<div id="area_div" style="margin-left: 10px"></div>--%>
	</div>
</div>
 <div class="row">
		 <div class="col-xs-12">
		 	<div class="box">
		 		<div class="box-header">
	                 <h3 class="box-title">商户列表</h3>
	             </div>
	             <!-- 列表 -->
	             <div class="box-body table-responsive">
	             	<table id="dataTables" class="table table-bordered table-hover">
	             	</table>
	             </div>
		 	</div>
		 </div>
	</div>
<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
<!-- datatable -->
<script src="${ctx}/static/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
<script src="${ctx}/static/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
<script src="${ctx}/static/js/common/area.js" type="text/javascript"></script>
<script>
   var tb;
   $(function () {
		//列表初始化
		tb = $('#dataTables').dataTable({
				"bServerSide": true,
				"sPaginationType": "full_numbers",
				"bJQueryUI": true,
				"sDom": '<"">t<"F"ip>',
            "sAjaxSource": "${ctx}/api/merchant/list?agentId=${agent.id}", //ajax调用接口
				"aoColumnDefs": [{sDefaultContent: '',aTargets: [ '_all' ]}],
	       		"aoColumns": [
		                { "sTitle" : "序号","mData": "id","class":"sClass" },
		                { "sTitle" : "商店名称","mData": "merchantName","class":"sClass" },
		                { "sTitle" : "商户联系人","mData": "personName","class":"sClass" },
		                { "sTitle" : "联系人电话","mData": "merchantTel","class":"sClass" },
                    /* { "sTitle" : "上级代理名字","mData": "agentName","class":"sClass" }, */
                    {"sTitle": "社区", "mData": "townName", "class": "sClass"},
                    {
                        "sTitle": "区域", "mData": "roleName", "class": "sClass", "mRender": function (data, type, full) {
		                	var text;
                        if (!(full.provinceName === null)) {
                            text = full.provinceName;
                        }
                        if (!(full.cityName === null)) {
                            text = text + "-" + full.cityName;
                        }
                        if (!(full.countyName === null)) {
                            text = text + "-" + full.countyName;
                        }
	                    	return text;
	        				}
		                },
		                { "sTitle" : "推广师电话","mData": "promoterTel","class":"sClass" },
		                { "sTitle" : "推广师名字","mData": "promoterName","class":"sClass" },
                    {
                        "sTitle": "状态", "mData": "status", "class": "sClass", "mRender": function (data, type, full) {
                        var text;
                        if (full.status == '1') {
                            text = "<font color='blue'>正常</font>";
                        } else if (full.status == '3') {
                            text = "<font color='green'>冻结</font>"
                        }
                        return text;
                    }
		                },
		                {"sTitle" : "操作","mData" : "id", "mRender" : function ( data, type, full ) {
	                	  var text = '<div class="btn-group" style="text-align:left;"><button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">操作 <span class="caret"></span></button>';
							  text = text+'<ul class="dropdown-menu" role="menu">';
                            text += '<li class="divider"></li>';
							  text += '<li><a href="#" onclick="merchantDetail(\''+full.id+'\');">商户详细</a> </li>';
							  text += '<li class="divider"></li>';
                            <%--text += '<li><a href="${ctx}/api/merchant/merchantBalancePage?manageId='+full.id+'">商户余额记录</a> </li>';--%>
                            <%--text += '<li class="divider"></li>';--%>
                            <%--text += '<li><a href="#" onclick="toUpdateMerchantAndMerchantImage(\''+full.id+'\');">商户修改</a> </li>';--%>
                            <%--if(full.status == '1'){--%>
                            <%--text += '<li class="divider"></li>';--%>
                            <%--text += '<li><a href="#" onclick="blackHome(\'' + full.id + '\',\''+full.merchantTel+'\');">冻结</a> </li>';--%>
                            <%--}else if(full.status == '3'){--%>
                            <%--text += '<li class="divider"></li>';--%>
                            <%--text += '<li><a href="#" onclick="openBlackHome(\'' + full.id + '\',\''+full.merchantTel+'\');">解冻</a> </li>';--%>
                            <%--}--%>
                            text = text + '</ul></div>';
							  return text;
							} 
		                }
	            ],
		        "oLanguage" : {
		           "sProcessing" : "数据加载中······",
		           "sLengthMenu" : "显示 _MENU_ 条记录",
		           "sZeroRecords" : "没有您要搜索的内容！",
		           "sEmptyTable" : "列表中无数据存在！",
		           "sInfo" : "当前显示 _START_ 到 _END_ 条数据，共 _TOTAL_ 条数据",
		           "sInfoEmpty" : "显示 0 到 0 条记录",
		           "sInfoFiltered" : "数据列表中共  _MAX_ 条记录",
		           "oPaginate" : {
		               "sFirst" : "首页",
		               "sPrevious" : "上一页",
		               "sNext" : "下一页",
		               "sLast" : "末页"
		           }
		        },
		        "fnServerData" : function ( sSource, aoData, fnCallback, oSettings ) {
					oSettings.jqXHR = $.ajax( {
						"dataType" 	: 'json',
						"type" 		: "GET",
						"async"     : 'false',
						"url" 		: sSource,
						"data" 		: {
							'pageNum': (aoData[3].value/aoData[4].value)+1,
							'pageSize' :  aoData[4].value,
							'merchantName'  :  $("#merchantName").val(),
							'merchantTel'  :  $("#merchantTel").val(),
							'promoterTel'  :  $("#promoterTel").val(),
                            'provinceId': $("select[name='provinceId']").val(),
                            'cityId': $("select[name='cityId']").val(),
                            'countyId': $("select[name='countyId']").val(),
                            'townId': $("select[name='townId']").val(),
                            'status': 5,
                            'provinceId': $("select[name='provinceId']").find("option:selected").attr("data-area-code"),
                            'cityId': $("select[name='cityId']").find("option:selected").attr("data-area-code"),
                            'countyId': $("select[name='countyId']").find("option:selected").attr("data-area-code"),
                            'townId': $("select[name='townId']").find("option:selected").attr("data-area-code"),
						}, 
						"success"	: fnCallback
					} );
				},
		  });
   });
   
   //条件查询重新加载数据
   function query() {
	   tb.fnDraw();
       /* 	   $("#merchantTel").val("");
	   $("#merchantName").val("");
        $("#promoterTel").val(""); */
   }
   //获取商户详细  
   function merchantDetail(merchantId){
	   window.location.href="/api/merchant/merchantDetail?id="+merchantId;
   }
   //跳转修改商户页面 
   function toUpdateMerchantAndMerchantImage(merchantId){
	   window.location.href="/api/merchant/toUpdateMerchantAndMerchantImage?id="+merchantId;
   }
   //跳转商户的余额记录页面 
   function merchantBalancePage(merchantId) {
       window.location.href = "/api/merchant/balanceMerchantPage?manageId=" + merchantId;
   }

   //冻结
   function blackHome(id, merchantTel) {
       if (confirm("确认冻结该商户?") == true) {
           $.ajax({
               async: false,
               url: "/api/merchant/updateMerchatStatues",
               data: {id: id, status: 3, merchantTel: merchantTel},
               type: "POST",
               dataType: "json",
               success: function (data) {
                   if (data.code == "200") {
                       tb.fnDraw();
                   } else {
                       alert(data.message);
                   }
               }
           });

       } else {
           return false;
       }
   }

   //解冻
   function openBlackHome(id, merchantTel) {
       if (confirm("确认解冻该商户?") == true) {
           $.ajax({
               async: false,
               url: "/api/merchant/updateMerchatStatues",
               data: {id: id, status: 1, merchantTel: merchantTel},
               type: "POST",
               dataType: "json",
               success: function (data) {
                   if (data.code == "200") {
                       tb.fnDraw();
                   } else {
                       alert(data.message);
                   }
               }
           });

       } else {
           return false;
       }
   }
	
   areaAll({
       url: "/api/merchant/getAllPosition",
       startFun: function () {
           $("#area_div").find(".formError").remove();
       },
       totalSelect: 4,
       DivId: "area_div",
       selectWidthArr: ["90px", "90px", "90px", "90px"],
       areaArr: ["省份:", "市:", "区县:", "社区:"],
       idArr: ["provinceId", "cityId", "countyId", "townId"],
       isNeedName: false,
       spaceArrLeft: [5, 5, 5, 5],
       spaceArrRight: [5, 5, 5, 5],
       data: null,
       backFun: null
   })
</script>
</body>
</html>